<?php include('config.php');
session_start();
if (!empty($_POST['user_name'])&&  !empty($_POST['user_email']) && !empty($_POST['user_mobile'])){
	
	$sql="INSERT INTO fawri_users (user_name,user_email,user_mobile,user_fbid,user_score,last_access) VALUES 
		('".$_POST["user_name"]."','".$_POST["user_email"]."','".$_POST["user_mobile"]."','".$_SESSION ['id']."',0,'')";
		if (!mysql_query($sql,$con))
		{
			die('Error: ' . mysql_error());
		}

} 

mysql_close($con);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Fawri | Nav</title>
<!-- STYLES -->
<link rel="stylesheet" type="text/css" href="css/style.css" />
<script src="js/jquery-1.8.3.min.js"></script>
</head>


<body>
<div id="fb-root"></div>

<script>
var id=0;
var check="";
  // Additional JS functions here
  window.fbAsyncInit = function() {
    FB.init({
      appId      : '429014180529532', // App ID
      channelUrl : '//WWW.bee-interactive.net/assets/testauth/channel.html', // Channel File
      status     : true, // check login status
      cookie     : true, // enable cookies to allow the server to access the session
      xfbml      : true  // parse XFBML
    });

    // Additional init code here
	
	FB.getLoginStatus(function(response) {
	  if (response.status === 'connected') {
		// connected
	 
     
     FB.api('/me', {"access_token":FB.getAuthResponse()['accessToken']},{},function(response) {
     window.id= response.id ;
	$('.nav').fadeIn(500);
	//alert (x);

     });
	  } else if (response.status === 'not_authorized') {
		// not_authorized
		login();
	  } else {
		// not_logged_in
		login();
	  }
	 });

  };
  


	function login() {
		FB.login(function(response) {
			if (response.authResponse) {
				// connected
				testAPI();
			} else {
				// cancelled
			}
		},{scope: 'email,user_birthday'});
	}
	
	function testAPI() {
		FB.api('/me', function(response) {
			window.id=response.id ;
		});
		 
	}
	
$(document).ready(function(e) {
	$('.nav').hide();
	$('.start').click(function(event){
		event.preventDefault();
		//alert (window.id);
			$.get('check.php',
					{ data:window.id}, 
					 function(data) {
						window.check = data.replace(/\s+/g, ' ');;
						//alert(window.check);
						if (window.check===" true"){
								self.location.href = 'question-page.php';
							}else {
								self.location.href = 'register.php';
						}
			}); 
	});
});
  // Load the SDK Asynchronously
  (function(d){
     var js, id = 'facebook-jssdk', ref = d.getElementsByTagName('script')[0];
     if (d.getElementById(id)) {return;}
     js = d.createElement('script'); js.id = id; js.async = true;
     js.src = "//connect.facebook.net/en_US/all.js";
     ref.parentNode.insertBefore(js, ref);
   }(document));
</script>

    <!-- APP WARPER -->
    <div class="warper">
    	<!-- content left side -->
    	<div class="left-side">
        	<div class="content">
            	<!-- Main Header -->
                <div class="nav">
                	<a href="terms.php" class="play">طريقة <br />اللعب</a>
                    <a href="#" class="start">ابدأ <br />المسابقة</a>
                    <a href="about.php" class="terms">الشروط و<br /> الأجكام</a>
                </div>
                <!-- Reguster Box -->
                
            </div>
            <!-- back btn -->
           
        </div>
        <div class="right-side">
        	<a href="#" class="logo">
            	
            </a>
            <span class="side-prize"></span>
        </div>
    </div>
</body>
</html>
